"""
运行程序，打开浏览器访问以下url：
http://127.0.0.1:8080

"""
import socket
import datetime

HOST, PORT = "localhost", 9999

sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((HOST, PORT))
sock.listen()
print('Serving HTTP on port %s ...' % PORT)

while True:
    request, address = sock.accept()
    print("[{}] {}".format(datetime.datetime.now(), address))
    received = request.recv(1024)
    print("[{}] {} {}".format(datetime.datetime.now(), address, received))
    request.sendall(received.lower())
    request.close()
